<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/leek_bbs/statics/yu-ui/js_css/yu.css">
    <link rel="stylesheet" href="/leek_bbs/statics/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/leek_bbs/statics/layui/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <input type="hidden" id="uid" name="id" value="">
            <div class="layui-form-item">
                <label class="layui-form-label required">管理账号</label>
                <div class="layui-input-block">
                    <input type="text" name="username" id="user-name" lay-verify="required" lay-reqtext="管理账号不能为空" placeholder="请输入管理账号"  value="" class="layui-input" disabled>
                    <!--<tip>填写自己管理账号的名称。</tip>-->
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">手机</label>
                <div class="layui-input-block">
                    <input type="number" id="phone" name="phone" lay-verify="required|phone" lay-reqtext="手机不能为空" placeholder="请输入手机"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="email" id="email" name="email" lay-verify="required|email"  placeholder="请输入邮箱"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-upload-drag" id="pictureUpload">
                        <i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>
                        <div class="layui-hide" id="uploadDemoView">
                            <hr>
                            <img src="" alt="上传成功后渲染" style="max-width: 196px">
                        </div>
                    </div>
                </div>
                <input type="hidden" id="picture" name="picture" value="">
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/leek_bbs/statics/component/common_import.js" charset="utf-8"></script>
<script src="/leek_bbs/statics/layui/lay-config.js" charset="utf-8"></script>
<script>
    layui.use(['form','miniTab','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            upload = layui.upload;

        let adminInfo = JSON.parse(localStorage.getItem("adminInfo"));
        addValue();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            axios.post('/leek_bbs/stair/datum/alterUser',data.field).then(result => {
                let res = result.data;
                if (res.code == "500020") {
                    ui.success("资料保存成功",1500,true);
                    localStorage.removeItem("adminInfo");
                    parent.window.getAdminInfo(data.field.username);
                    setTimeout(()=>{
                        miniTab.deleteCurrentByIframe();
                    },1000);
                }else if (res.code == "500033") {
                    ui.error(res.msg,1000,true);
                }else {
                    ui.error("系统出现了一个未知异常",1500,true);
                }
            }).catch(error => {
                ui.error("请求出现异常",1500,true);
            });

            return false;
        });

        form.verify({
            password: [
                /^[\S]{6,16}$/
                ,'密码必须6到16位，且不能出现空格'
            ]
            ,phone: [/^1[3|4|5|7|8]\d{9}$/, '手机号格式不对！']
            ,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
        });

        upload.render({
            elem: '#pictureUpload'
            ,url: '/leek_bbs/bbs/file/fileupload'
            /*,data: {
                id: function(){
                    return adminInfo.id;
                }
            }*/
            ,done: function(res){
                if(res.code == 0){
                    let username = adminInfo.username;
                    ui.success('头像上传成功',2000,true);
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src','/leek_bbs/'+res.picture);
                    $("#picture").val(res.picture);
                }else {
                    ui.error('头像上传失败',2000,true);
                }
            }
        });

        function addValue() {
            $("#uid").val(adminInfo.id);
            $("#user-name").val(adminInfo.username);
            $("#email").val(adminInfo.email);
            $("#phone").val(adminInfo.phone);
        }
    });
</script>
</body>
</html>